package parser

import (
	"gitee.com/shu2015626/go_start_imooc/chapter13-crawler/single_crawler/engine"
	"regexp"
)

const cityRe = `<a href="(http://album.zhenai.com/u/[0-9]+)"[^>]*>([^<]+)</a></th>`

func ParseCity(contents []byte) engine.ParseResult {
	re := regexp.MustCompile(cityRe)
	matches := re.FindAllSubmatch(contents, -1)

	result := engine.ParseResult{}
	for _, m := range matches {
		name :=  string(m[2])
		result.Items = append(result.Items, "User: " + name)
		result.Requests = append(result.Requests, engine.Request{
			Url:        string(m[1]),
			ParserFunc: func(contents []byte) engine.ParseResult{
				return ParseProfile(contents, name)
			},
		})
	}
	return result
}
